/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.googlecode.mindlistening.freemind;

import com.googlecode.mindlistening.ConversationControllerImpl;
import freemind.controller.MapModuleManager.MapModuleChangeObserver;
import freemind.modes.MindMapNode;
import freemind.modes.Mode;
import freemind.view.MapModule;

/**
 *
 * @author ryan
 */
public class FreemindModeListener implements MapModuleChangeObserver {

    ConversationControllerImpl conversationController;
    FreeMindPropertiesStorage p_storage;

    public FreemindModeListener(ConversationControllerImpl conversationController, FreeMindPropertiesStorage p_storage) {
        this.conversationController = conversationController;
        this.p_storage = p_storage;
    }

    @Override
    public void afterMapModuleChange(MapModule oldMapModule, Mode oldMode, MapModule newMapModule, Mode newMode) {
        //System.out.println("Map changed!!!");
        if (newMapModule != null) {
            MindMapNode node = newMapModule.getModeController().getController().getMap().getRootNode();
            FreeMindNodeDocumentStorage d_storage = new FreeMindNodeDocumentStorage(node, p_storage);
            conversationController.changeDocument(d_storage);
        }
    }

    @Override
    public boolean isMapModuleChangeAllowed(MapModule mm, Mode mode, MapModule mm1, Mode mode1) {
        return true;
    }

    @Override
    public void beforeMapModuleChange(MapModule mm, Mode mode, MapModule mm1, Mode mode1) {
    }

    @Override
    public void afterMapClose(MapModule mm, Mode mode) {
        //conversationController.stopPlayback();
    }

    @Override
    public void numberOfOpenMapInformation(int i) {
    }
}
